package priv.pront.code.lanqiao.team.comp.mati_2;

import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-02 21:20
 */
public class P2670_扫雷游戏 {

    static int n, m;
    static char[][] g, ans;
    static int[][] values;
    static int[] dx = {1, 1, 0, -1, -1, -1, 0, 1};
    static int[] dy = {0, 1, 1, 1, 0, -1, -1, -1};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        g = new char[n][m];
        ans = new char[n][m];
        values = new int[n][m];
        for (int i = 0; i < n; i++) {
          g[i] = scanner.next().toCharArray();
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(g[i][j] == '*'){
                    add(i, j);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == '*') {
                    ans[i][j] = '*';
                }else{
                    String value = values[i][j] + "";
                    ans[i][j] = value.charAt(0);
                }
                System.out.print(ans[i][j]);
            }
            System.out.println();
        }
    }

    private static void add(int i, int j) {
        for (int k = 0; k < 8; k++) {
            int x = i + dx[k];
            int y = j + dy[k];
            if (x >= 0 && y >= 0 && x < n && y < m) {
                values[x][y]++;
            }
        }
    }
}
